/**
 * 角色管理相关API
 */
import { BaseApiService } from './base'
import request from '@/utils/request'
import type { Role } from '@/types'

export class RoleService extends BaseApiService {
  constructor() {
    super('/role')
  }

  /**
   * 获取所有角色
   */
  async getAllRoles() {
    return request.get('/role/getAllRole')
  }

  /**
   * 创建角色
   */
  async createRole(name: string) {
    return request.get(`/role/addRoleOnlyName?name=${name}`)
  }

  /**
   * 更新角色
   */
  async updateRole(id: string | number, name: string) {
    return request.get(`/role/updateRoleName?id=${id}&name=${name}`)
  }

  /**
   * 更新角色数据
   */
  async updateRoleData(data: Role) {
    return request.post(`/role/updateRole`,data)
  }

  /**
   * 删除角色
   */
  async deleteRole(id: string | number) {
    return request.delete(`/role/deleteRole?id=${id}`)
  }

  /**
   * 获取角色权限
   */
  async getRolePermissions(id: string | number) {
    return request.get(`/role/permissions/${id}`)
  }

  /**
   * 设置角色权限
   */
  async setRolePermissions(id: string | number, permissions: any[]) {
    return request.post(`/role/setPermissions/${id}`, { permissions })
  }
}

export const roleService = new RoleService()
export default roleService
